DEW.DetailsController = function() {};

$.extend(DEW.DetailsController.prototype, {
    render: function() {
        DEW.ViewManager.removeAll();
        this.displayLayout();
        this.displayHeader();
        this.displayBody();
        this.displayFooter();
    },

    displayLayout: function() {
        var detailsLayout = new DEW.DetailsLayout();
        detailsLayout.render();
        $(detailsLayout.el).appendTo("#content");
        DEW.ViewManager.addView(detailsLayout);
    },

 displayHeader: function() {
        var header = new DEW.Header({
            logo: {
                src: 'images/logo.jpg',
                alt: 'Logo'
            },
            enlaces: [{
                    id:0,
                    text:'Home',
                    show:true,
                    textonly:false,
                    url: 'home',
                    handler:function(){                      
                    var Home = new DEW.BaseLayout();
                     Home.render();
                     $("#body").append(Home.el);
                }
            },{
                    id:1,
                    text: 'Que es?',
                    show:true,
                    textonly: false,
                       handler:function(){
                    var WhatIs = new DEW.What();
                     WhatIs.render();
                     $("#body").append(WhatIs.el);
                }
            },{
                    id: 2,
                    text: 'Apoya un Proyecto',
                    show:true,
                    textonly: false,
                     handler:function(){
                    var ApoyaProject = new DEW.ListProject();
                     ApoyaProject.render();
                     $("#body").append(ApoyaProject.el);
                }
                },{
                    id:3,
                    text: 'Registrate',
                    show:true,
                    textonly: false,
                    handler:function(){
                        
                    }
                }]
        });
        header.render();
        $(header.el).appendTo("#header");
    },

    displayBody: function() {
        var listCollection = DEW.StoreManager.get('CommentsCollection');
        if (listCollection === null) {
            listCollection = new DEW.ListCollection();
            listCollection.fetch({reset:true});
            listCollection.on('reset',function() {
                var itemModel = listCollection.getItem(DEW.itemID).toJSON();
                var itemView = new DEW.Item({
                    model: itemModel
                });
                itemView.render();
                $(itemView.el).appendTo("#page-content");
                DEW.ViewManager.addView(itemView);
            });
        } else {
            //Para mejorar la velocidad no recargo todo sino que reutilizo el codigo
            var itemModel = listCollection.getItem(DEW.itemID).toJSON();
            var itemView = DEW.Item({
                model: itemModel
            });
            itemView.render();
            $(itemView.el).appendTo("#page-content");
            DEW.ViewManager.addView(itemView);
        }
    },

    displayFooter: function() {
        var footer = new DEW.Footer();
        footer.render();
        $(footer.el).appendTo("#footer");
    }

});